<template>
  <!-- 发货-->
  <div>
    <div class="rdioSelect aliCenter">
      <div
        @click="selectFn(index)"
        :class="item.select ? 'rdio' : 'rdio2'"
        v-for="(item, index) in radioData"
        :key="index"
      >
        {{ item.title }}
      </div>
    </div>
    <div class="inputSerachBox">
      <div class="inputSerachBox2">
        <input
          type="text"
          class="inputSerach"
          v-model="serchData"
          :placeholder="$t('messages.Shipment.serach')"
        />
        <div class="blackCircle center" @click="serchFn">
          <el-icon color="white" class="RigthIcon"><Right /></el-icon>
        </div>
      </div>
    </div>
    <div class="list">
      <div class="listBox" v-for="(item, index) in deliverList" :key="index">
        <div class="card">
          <div class="cardTop title aliCenter" style="justify-content: space-between">
            <div>Warranty Serial Number： {{ item.filmNo }}</div>
            <div>Shipping Time： {{ dayjs(item.create_time).format('YYYY-MM-DD') }}</div>
          </div>
          <div class="cardContent">
            <el-row>
              <el-col :span="14">
                <el-col :span="24" class="col size2">
                  <div>Product Type： {{ item.filmType }}</div>
                </el-col>
                <el-col :span="24" class="col size2">
                  <div>Product Model： {{ item.filmName }}</div>
                </el-col>
                <el-col :span="24" class="col size2">
                  <div>Product Usage Count： {{ item.number }}</div>
                </el-col>
                <el-col :span="24" class="col size2">
                  <div>Sender Harbor： {{ item.deliverStoreName }}</div>
                </el-col>
                <el-col :span="24" class="col size2">
                  <div>Receiving Store： {{ item.storeName }}</div>
                </el-col>
                <el-col :span="24" class="col size2">
                  <div>Receiver： {{ item.linkman }}</div>
                </el-col>
                <el-col :span="24" class="col size2">
                  <div>Total Usage Count： {{ item.count }}</div>
                </el-col>
              </el-col>
            </el-row>
          </div>
          <div v-if="item.deliverStatus == 1" class="button Consigness">Received</div>
          <div v-else-if="item.deliverStatus == 2" class="button Rejection">Reject</div>
        </div>
      </div>
    </div>
    <div class="pageButton center" v-if="total > 0">
      <div>
        <el-icon @click="pageFn(-1)" class="ArrowLeftBold" size="50" :color="ArrowLeftBoldColor"
          ><ArrowLeftBold
        /></el-icon>
      </div>
      <div>
        <el-icon @click="pageFn(1)" class="ArrowRightBold" size="50" :color="ArrowRightBoldColor"
          ><ArrowRightBold
        /></el-icon>
      </div>
    </div>
  </div>

  <!-- 放大图片 -->
  <el-dialog
    class="el-dialog__body2"
    v-model="dialogVisibleMagnifyFn"
    :show-close="false"
    :before-close="handleClose"
  >
    <div class="bakImg">
      <img :src="upImg" alt="" srcset="" />
    </div>
  </el-dialog>
</template>

<script setup>
import { storeDeliverList } from '@/http/api/my.js'
import { Delete, Search } from '@element-plus/icons-vue'
import { ref, reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import dayjs from 'dayjs'
let dialogVisibleMagnifyFn = ref(false)
let dialogVisibleAddVehicleFn = ref(false)
let formData = reactive({})
let inputFile = ref(null)
let upImg = ref('')
let radioData = ref([
  {
    title: 'Shipped',
    select: true,
    status: 0
  }, {
    title: 'Received',
    select: false,
    status: 1
  }, {
    title: 'Reject',
    select: false,
    status: 2
  }
])
let selectRdio = ref(0)
let deliverStatus = ref(0)
let deliverList = ref([])
let pageData = reactive({
  page: 1,
  size: 10
})
let storeId = JSON.parse(localStorage.getItem('storeInfo')).id
let serchData = ref('')
const selectFn = (number) => {
  ArrowRightBoldColor.value = '#ffdd00'
  ArrowLeftBoldColor.value = '#ffdd00'
  selectRdio.value = number
  radioData.value.forEach((item, index) => {
    if (index == number) {
      item.select = true
      deliverStatus.value = item.status
      getStoreDeliverFn()
    } else {
      item.select = false
    }
  })
}
const magnifyFn = () => {
  dialogVisibleMagnifyFn.value = true
}
const addVehicleFn = () => {
  dialogVisibleAddVehicleFn.value = true
}
const upImgFn = () => {
  inputFile.value.addEventListener('change', async function (event) {
    var files = event.target.files[0]
    const formData = new FormData()
    //files 文件信息
    formData.append("uploadFiles", files)
    //提交的其他字段
    // 发送ajax请求
    const res = await uploadAvatar(formData)
    upImg.value = res.image_url

  })
  // 将input添加到文档中
  // document.body.appendChild(input);
  inputFile.value.click()
}
// 搜索
const serchFn = async () => {
  getStoreDeliverFn()
}
let total = ref(0)
// 获取发货列表
const getStoreDeliverFn = async () => {
  let data = {
    ...pageData,
    storeId,
    serchData: serchData.value,
    deliverStatus: deliverStatus.value
  }
  let res = await storeDeliverList(data)
  total.value = res.total
  deliverList.value = res.res.map(item => {
    return {
      ...item,
      filmType: item.filmType == '漆面膜' ? 'TPU PPF' : item.filmType == '改色膜' ? 'COLOR PPF' : item.filmType == '车顶膜' ? 'WINDOW FILM' : 'SUNROOL FILM'
    }
  })


  if (pageData.page * pageData.size <= 10) {
    ArrowLeftBoldColor.value = '#717171'
  }
  if (total.value <= 10) {
    ArrowRightBoldColor.value = '#717171'
  }
}
let ArrowLeftBoldColor = ref('#ffdd00')
let ArrowRightBoldColor = ref('#ffdd00')

const pageFn = (data) => {
  if (data < 0) {
    if (pageData.page * pageData.size != 10) {
      pageData.page = pageData.page + data == 0 ? 1 : pageData.page + data
      getStoreDeliverFn()
      ArrowRightBoldColor.value = '#ffdd00'
    } else {
      ArrowLeftBoldColor.value = '#717171'
    }
  } else {
    if (pageData.page * pageData.size <= total.value) {
      pageData.page = pageData.page * pageData.size < total.value ? pageData.page + data : pageData.page
      getStoreDeliverFn()
      ArrowLeftBoldColor.value = '#ffdd00'
      console.log(pageData.page * pageData.size > total.value)
      if (pageData.page * pageData.size >= total.value) {
        console.log(ArrowRightBoldColor)
        ArrowRightBoldColor.value = '#717171'
      }
    } else {
      ArrowRightBoldColor.value = '#717171'
    }
  }

}
const deleteImgFn = () => {
  upImg.value = ''
}
onMounted(() => {
  getStoreDeliverFn()
})
</script>

<style lang="scss" scoped>
.listBox {
  width: 100%;
  margin-top: 45px;
  margin-left: 50px;
  .card {
    width: 1800px;
    border-radius: 20px;
    overflow: hidden;
    background: #1a1c1d;
    position: relative;
    .cardTop {
      height: 100px;
      width: 100%;
      background: #ffdd00;
      padding: 0 20px;
      font-weight: bold;
      color: black;
    }
    .cardContent {
      padding: 10px 40px;
      font-size: 24px;
      color: white;
      height: 500px;
    }
  }
}
.listBotton {
  width: 100%;
  .botton {
    width: 170px;
    height: 70px;
    background: #ffdd00;
    font-weight: bold;
    font-size: 18px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;

    color: black;
    margin-top: 20px;
  }
  .botton:active {
    background: black;
    color: white;
  }
}
.AddVehiclenCard {
  width: 1800px;
  height: 400px;
  border-radius: 20px;
  overflow: hidden;
  background: #1a1c1d;
  .AddVehiclenCardTop {
    height: 100px;
    width: 100%;
    background: #ffdd00;
    font-size: 24px;
    padding: 0 20px;
    font-weight: bold;
    color: black;
  }
}
.AddVehiclenCardContent {
  display: flex;
  padding: 10px;
  .left {
    margin-right: 30px;
    margin-left: 50px;
  }
}
.upImg {
  background: #3c3c3c;
  width: 260px;
  height: 260px;
  border-radius: 20px;
  font-size: 50px;
  cursor: pointer;
}

.imgBox {
  width: 260px;
  height: 260px;
  border-radius: 20px;
  position: relative;
  left: 0;
  top: 0;
  img {
    width: 100%;
    height: 100%;
  }
  .Mask {
    background: black;
    opacity: 0;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    justify-content: space-around;
    font-size: 30px;
  }
  .Mask:hover {
    opacity: 0.6;
  }
  cursor: pointer;
}

.bakImg {
  width: 800px;
  height: 800px;
  img {
    width: 100%;
    height: 100%;
  }
}
::v-deep .el-dialog__body2 {
  width: 800px !important;
}
::v-deep .el-form-item__label {
  font-size: 30px;
  color: white;
}
::v-deep .el-radio__input.is-checked .el-radio__inner {
  background: #ffdd00;
  border: #ffdd00;
}
::v-deep .el-radio__input .is-checked {
  color: white !important;
  font-size: 24px;
}
.col {
  width: 100%;
  height: 40px;
  margin-top: 20px;
}
::v-deep .el-radio__label {
  color: white !important;
  font-size: 24px;
}
::v-deep .el-input {
  height: 40px;
}
::v-deep .el-input__wrapper {
  background: #242424 !important;
  border: 1px solid rgb(255, 221, 0);
  box-shadow: 0 0 !important;
}
.inpute1 {
  width: 800px;
}
.inpute2 {
  width: 1300px;
}

.cofimButton {
  width: 220px;
  height: 70px;
  background: #ffdd00;
  border-radius: 20px;
  font-size: 30px;
  font-weight: bold;
  color: black;
  cursor: pointer;
}
.cofimButton:active {
  background: black;
  color: white;
}
.qualityImg {
  width: 700px;
  height: 480px;
  img {
    width: 100%;
    height: 100%;
  }
}
.button {
  width: 180px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  bottom: 10px;
  right: 50px;
  border-radius: 20px;
  font-weight: bold;
  font-size: 22px;
  color: black;
}
.Consigness {
  border: 1px solid #85ce61;
  color: #85ce61;
}
.Rejection {
  border: 1px solid #ff1f1f;
  color: #ff1f1f;
}
.rdioSelect {
  margin-top: 50px;
  margin-left: 50px;
  margin-bottom: 50px;
  .rdio {
    font-weight: bold;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #ffdd00;
    margin-right: 20px;
  }
  .rdio2 {
    font-weight: bold;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    margin-right: 20px;
  }
}

.inputSerach::placeholder {
  font-size: 18px;
}
.inputSerach {
  border: none;
  width: 950px;
  height: 70px;
  border-radius: 20px;
}
.inputSerach:focus {
  border: none !important;
  outline: none;
}
.inputSerachBox {
  padding-left: 50px;
  position: relative;
  cursor: pointer;
}
.inputSerachBox2 {
  cursor: pointer;
  width: 1800px;
  height: 70px;
  border-radius: 20px;
  background: white;
}
.blackCircle {
  background: black;
  width: 60px;
  height: 60px;
  border-radius: 30px;
  position: absolute;
  right: 65px;
  top: 50%;
  transform: translateY(-50%);
}
.RigthIcon {
  font-size: 25px;
}
.pageButton {
  width: 100%;
  margin-top: 20px;
}
px .storeListRow {
  height: 300px;
  margin-top: 10px;
}
.ArrowLeftBold {
  cursor: pointer;
}
.ArrowRightBold {
  cursor: pointer;
}
.ArrowLeftBold:active {
  color: black;
}
.ArrowRightBold:active {
  color: black;
}
</style>